package com.jqr.activity.myroomcart;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;
import android.view.View;

import com.jqr.activity.myroomcart.dao.BookDao;
import com.jqr.activity.myroomcart.databinding.ActivityMainBinding;
import com.jqr.activity.myroomcart.viewmodels.MainViewModel;

public class MainActivity extends AppCompatActivity {

    private MainViewModel mainViewModel;
    private ActivityMainBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mainViewModel=new ViewModelProvider(this).get(MainViewModel.class);
        // AndroidViewModel
       // mainViewModel=new ViewModelProvider(this,new ViewModelProvider.AndroidViewModelFactory(getApplication())).get(MainViewModel.class);
        //ViewModel
       // mainViewModel=new ViewModelProvider(this,new ViewModelProvider.NewInstanceFactory()).get(MainViewModel.class);
       // BookDao bookDao=MyApplication.getInstance().getBookDB().bookDao();
        binding= DataBindingUtil.setContentView(this,R.layout.activity_main);
        binding.setVm(mainViewModel);
        binding.setLifecycleOwner(this);

        binding.btnClick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mainViewModel.getName().setValue("Hello kotlin java");
            }
        });

    }
}